<template>
  <div class="content">
    <headline v-bind:title="title"></headline>
    <div class="filter">
      <el-form label-width="150px">
        <el-row>
          <el-col :span="12">
            <el-form-item label="所属品类">
              <el-select v-model="value" placeholder="请选择/搜索选择" class="input">
                <el-option v-for="item in arr" :key="item.value" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="品类管理">
              <el-input v-model="name" placeholder="请输入品类名称" class="input"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <below v-bind:shwHde="shwHde"></below>
  </div>
</template>
<script>
import headline from "../headline.vue";
import below from "@/views/below";

export default {
  components: {headline, below},
  data() {
    return {
      title: '品类管理--添加品类',
      shwHde: [true, true],
      list: [],
      arr: [],
      value: "",
      name: "",
    };
  },
  mounted() {
    this.pinglei();
  },
  methods: {
    pinglei() {
      let postData = this.qs.stringify({categoryId: ''});
      this.axios({
        method: "POST",
        url: "/api/manage/category/get_category.do",
        data: postData,
      }).then((res) => {
        this.arr = res.data.data;
      });
    },
    tij() {
      let postData = this.qs.stringify({
        parentId: this.value,
        categoryName: this.name,
      });
      this.axios({
        method: "POST",
        url: "/api/manage/category/add_category.do",
        data: postData,
      }).then((res) => {
        this.$message({type: "success", message: res.data.data});
        if (res.data.status === 0) {
          this.$router.push({path: "category"});
        }
      });
    },
    // 返回按钮
    fanh() {
      this.$router.push({path: "/home/category"});
    },
  },
};
</script>
